/*
 * timer-ss805x.c
 *
 * timer driver for SS805X.
 *
 * Copyright (C) 2024 Sinh Micro, Inc.
 * Subject to the GNU Public License, version 2.
 *
 * Author: lixiang<lixiang@sinhmicro.com>
 * 
 * Encoding format: GB2312
 * Version: v1.2.2
 * Date: 2024-11-05
 */

#include "hal-config.h"
#include "hal-regs.h"
#include "timer.h"
#include "types.h"

#if (defined(CONFIG_SYS_CHIP_SERIES_SS805X))

#if (CONFIG_USING_TIMER0 == 1)
void t0_init(void)
{
    TCON1 = TCON1_VAL_TIMER0;

    TRL0 = TIMER0_RELOAD_VALUE;
    TRH0 = TIMER0_RELOAD_VALUE >> 8;  
}

uint16_t t0_reload_val_get(void)
{
    return TIMER0_RELOAD_VALUE;
}
#endif

#if (CONFIG_USING_TIMER2 == 1)
void t2_init(void)
{
    TCON0 = TCON0_VAL_TIMER2;

    TRL2 = TIMER2_RELOAD_VALUE;
    TRH2 = TIMER2_RELOAD_VALUE >> 8;  
    
#if (CONFIG_TIMER2_USING_IRQ == 1)
    INTEN1 |= 0x04;
#endif
}

uint16_t t2_reload_val_get(void)
{
    return TIMER2_RELOAD_VALUE;
}
#endif
#endif
